package pt.iscte.pcd.project.toolBox;

import java.io.UnsupportedEncodingException;
import javax.swing.JTextArea;

import pt.iscte.pcd.project.exceptions.FileSystemException;
import pt.iscte.pcd.project.local.LocalEntry;
import pt.iscte.pcd.project.local.LocalFile;

public class Tools {

	public static JTextArea readFile(LocalEntry file)
			throws FileSystemException, UnsupportedEncodingException, ClassCastException {
			JTextArea panel = new JTextArea();
			byte[] bytes = ((LocalFile) file).read();
			String decoded = new String(bytes, "windows-1252");
			panel.setEditable(false);
			panel.setText(decoded);
			
		return panel;
	}
	
	public static  void writeFile (LocalEntry file, byte[] string)
		throws FileSystemException, UnsupportedEncodingException, ClassCastException {
			((LocalFile)file).write(string);
	}
	
	public  static String[] listPath(String filePath, String separator) {
		return filePath.split(separator);
	}
}
